package com.zjs.jsp.ediorder.service.mongodb;

import com.zjs.jsp.domain.jsp.Jsp_Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Component;

/**
 * @author 李文
 * @create 2017-10-16 13:48
 **/
@Component
public class JspTaskTemplate
{

    @Autowired
    private MongoTemplate mongoTemplate;


    public void update(String tk, String i) {

        Query q = new Query();
        q.addCriteria(Criteria.where("tk").is(tk));
        q.addCriteria(Criteria.where("od.poc").is(i));

        Update update = new Update().set("od.$.cancel", "1");
        mongoTemplate.updateFirst(q, update, Jsp_Task.class);
    }

    public Jsp_Task findTask(String clientFlag, String i) {
        Query q = new Query();
        q.addCriteria(Criteria.where("clientFlag").is(clientFlag));
        q.addCriteria(Criteria.where("od.poc").is(i));
        return mongoTemplate.findOne(q, Jsp_Task.class);
    }

}
